{% extends "base.html" %}
{% import "_my_wtf_macros.html" as my_wtf_macros %}

{% block title %}万屏时代OPC--编辑项目{% endblock %}

{% block head %}
    {{ super() }}
    <link href="https://cdn.bootcss.com/fancybox/3.1.20/jquery.fancybox.min.css"
          rel="stylesheet">
{% endblock %}

{% block panel_heading %}
  万屏时代OPC--编辑项目
  <a
      class="btn btn-xs btn-success pull-right" style="margin-right: 5px"
      href="{{url_for('op_bp.user_visit_demand', demand_id=demand.id)}}"
      name="user-visit-demand"
      target="_blank"
    >工程商访问记录</a>
{% endblock %}

{% block panel_body %}
    <form class="form form-group-sm form-inline" id="edit-demand-form"
          action="{{ url_for('op_bp.edit_demand', demand_id=demand.id) }}"
          method="post" role="form" >

        <div class="well well-sm">项目信息
            {% if demand.is_ongoing and demand.is_install %}
                <a
                    class="btn btn-xs btn-primary pull-right"
                    href="{{ url_for('op_bp.import_users', demand_id=demand.id) }}"
                    name="import-users"
                    target="_blank"
                >
                    导入工程商
                </a>
            {% endif %}
        </div>
        {{ my_wtf_macros.form_field(form.id, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.uid, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.user_nickname, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.user_mobile, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.prov, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.city, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.addr, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.cate, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.malf, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.type, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.surr, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.color, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.span, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.size, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.bid_start_point, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.status, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.budget, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.tag, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.source, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.edit_created_at, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.edit_published_at, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        <div class="well well-sm">录音信息</div>
        <div class="form-group col-xs-12">
            <div class="row">
                {{ form.audio_id.label(class="control-label col-xs-2")|safe }}
                <div class="col-xs-10" id="audio-choices">
                    <a href="javascript:;" class="btn btn-info" id="sync_audio">同步录音</a>
                    <br>
                    <input type="checkbox" name="audio_sensitive"
                            {% if form.audio_sensitive.data %}
                           checked {% endif %}><span
                        style="color: red">是否敏感录音</span> <br>
                    {% for item in form.audio_id %}
                        <label class="control-label">
                            {{ item()|safe }}
                            {% if item.label.text==' ' %}
                                无录音
                            {% else %}
                                <audio src="{{ item.label.text|safe }}"
                                       controls="controls">
                                    您的浏览器无法播放该音频。
                                </audio>
                                录音日期：{{ audio_date_map[item._value()] }}
                            {% endif %}
                        </label>
                        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
                    {% endfor %}
                </div>
            </div>
        </div>

        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        <div class="form-group col-xs-1">
            <div class="row">
                <label class="control-label col-xs-12" for="remark">项目录音</label>
            </div>
        </div>
        <div class="form-group col-xs-11">
            <label class="control-label">
                {% if not demand.audio %}
                    无录音
                {% else %}
                    <audio src="{{ demand.audio_url|safe }}"
                           controls="controls">
                        您的浏览器无法播放该音频。
                    </audio>
                {% endif %}
            </label>
        </div>

        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        <div class="form-group col-xs-1">
            <div class="row">
                {{ form.remark.label(class="control-label col-xs-12")|safe }}
            </div>
        </div>
        <div class="form-group col-xs-11">
            {{ form.remark(class="form-control",rows="7")|safe }}
        </div>
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        {# 历史备注信息 #}
        {% if form.history_admin_remark.data %}
            <div class="form-group col-xs-1">
                <div class="row">
                    {{ form.history_admin_remark.label(class="control-label col-xs-12")|safe }}
                </div>
            </div>
            <div class="form-group col-xs-11">
                {{ form.history_admin_remark(class="form-control",rows="7")|safe }}
            </div>
            <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {% endif %}

        <div class="form-group col-xs-1">
            <div class="row">
                {{ form.admin_remark.label(class="control-label col-xs-12")|safe }}
            </div>
        </div>
        <div class="form-group col-xs-11">
            {{ form.admin_remark(class="form-control",rows="7")|safe }}
        </div>

        {% if form.publish_remark.data %}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        <div class="form-group col-xs-1">
            <div class="row">
                {{ form.publish_remark.label(class="control-label col-xs-12")|safe }}
            </div>
        </div>
        <div class="form-group col-xs-11">
            {{ form.publish_remark(class="form-control",rows="7")|safe }}
        </div>
        {% endif %}

        <!--计划外呼-->
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        <div id="outbound_record_info">
            <div class="well well-sm">计划外呼</div>

            <table id="schedule-outbound-records-table"
                   class="table table-bordered table-hover table-condensed table-striped">
                {% if schedule_outbound_records %}
                    <thead>
                    <tr>
                        <th>计划外呼时间</th>
                        <th>外呼原因</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for r in schedule_outbound_records %}
                        <tr>
                            <td>{{ r.schedule_time_display }}</td>
                            <td>{{ r.call_reason_display }}</td>
                            <td>
                                <a
                                        class="btn btn-xs btn-primary"
                                        href="{{ url_for('outbound_bp.cancel_outbound', record_id=r.id) }}"
                                        name="cancel-outbound"
                                >取消外呼</a><br>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                {% else %}
                    <tr>
                        <td>无</td>
                    </tr>
                {% endif %}
            </table>
        </div>

        <!--外呼记录-->
        {% if outbound_record or his_outbound_records %}
            <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
            <div id="outbound_record_info">
                <div class="well well-sm">外呼记录</div>
                {% if his_outbound_records %}
                    <table id="his-outbound-records-table"
                           class="table table-bordered table-hover table-condensed table-striped">
                    <thead>
                    <tr>
                        <th>拨打时间</th>
                        <th>发起方式</th>
                        <th>接听客服</th>
                        <th>转化结果</th>
                        <th>备注</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for r in his_outbound_records %}
                        <tr>
                          <td>{{ r.created_datetime }}</td>
                          <td>{{ r.call_type_display }}</td>
                          <td>{{ r.agent_name }}</td>
                          <td>{{ r.transform_result_display }}</td>
                          <td>{{ r.extra_info }}<td>
                        </tr>
                    {% endfor %}
                    </tbody>
                {% endif %}
                </table>
            </div>
        {% endif %}

        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        <div class="well well-sm col-md-12">跟进信息</div>
        <table class="table table-bordered table-hover table-condensed table-striped">
            <thead>
                <tr>
                    <th>竞标人昵称</th>
                    <th>跟进状态</th>
                    <th>跟进信息</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for each in follow_list %}
                    <tr>
                        <td>
                            <a href="{{ url_for('op_bp.user_info', user_id=each.owner.id) }}"
                               target="_blank">{{ each.owner.nickname }}</a>
                        </td>
                        <td>{{ each.follow_type_display }}</td>
                        <td>{{ each.follow_msg }}</td>
                        <td>
{#                            {% if each.follow_type not in (1, 3) %}#}
{#                            <a href="javascript:void(0);" class="btn btn-success btn-xs win_follow"#}
{#                                data-nickname="{{ each.owner.nickname }}" data-partic-id="{{ each.id }}"#}
{#                               data-follow-type="{{ each.follow_type }}" data-follow-msg="{{ each.follow_msg }}"#}
{#                            >#}
{#                                跟进#}
{#                            </a>#}
{#                            {% endif %}#}
                            <a class="btn btn-primary btn-xs" href="{{ url_for('axb_bp.win_bid_audio', demand_id=demand.id, client_id=demand.uid, win_user_id=each.supplier_id) }}">查看录音</a>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>

        <!--抢单信息/竞标信息-->
        <div class="well well-sm col-md-12">
            抢单信息
        </div>
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        {% if partics %}
            {% for partic in partics %}
                <div class="well well-sm">第{{ loop.index }}次发布</div>
                <table class="table table-bordered table-hover table-condensed table-striped">
                <thead>
                <tr>
                    <th>竞标人昵称</th>
                    <th>竞标点数</th>
                    <th>项目状态</th>
                    <th>抢单状态</th>
                    <th>抢单时间</th>
                    <th>中标时间</th>
                    <th>企业</th>
                    <th>获取真实号码</th>
                    <th>反馈信息</th>
                    <th>反馈备注</th>
                    <th>反馈时间</th>
                    <th>审核状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {% for each in partic %}
                <tr id="feedback-info">
                    <td>
                        <a href="{{ url_for('op_bp.user_info', user_id=each.owner.id) }}"
                           target="_blank">
                            {{ each.owner.nickname }}
                            {% if each.is_robot %}
                                (Robot)
                            {% endif %}
                            {% if each.is_training %}
                                (赠单)
                            {% endif %}
                        </a>
                    </td>
                    <td>{{ each.offer }}</td>
                    <td>{{ each.demand_status_display }}</td>
                    <td>{{ each.status_display }}</td>
                    <td>{{ each.offer_at_datetime or ''}}</td>
                    <td>{{ each.bid_win_at_display or ''}}</td>
                    <td>{{ each.enterprise_name}}</td>
                    <td>{{ each.apply_real_number_state_display}}</td>
                    <td>{{ each.feedback_display }}</td>
                    <td>{{ each.feedback_content }}</td>
                    <td>{{ each.feedback_at_display }}</td>
                    <td class="feedback-status">{{ each.feedback_status_display }}</td>
                    <td class="feedback-btn-group">
                        {% if each.feedback_status == 3 %}
                            {% if each.demand_status == 9 %}
                                <a class="btn-group btn btn-success feedback-btn btn-xs"
                                   data-partic_id="{{ each.id }}"
                                   data-feedback_status="2"
                                >返还派单点
                                </a>
                            {% else %}
                                <a class="btn-group btn btn-success feedback-btn btn-xs"
                                   data-partic_id="{{ each.id }}"
                                   data-feedback_status="2"
                                >返还汇币
                                </a>
                            {% endif %}

                            <a class="btn-group btn btn-danger feedback-refuse-btn btn-xs"
                               data-partic_id="{{ each.id }}"
                               data-feedback_status="1"
                            >驳回
                            </a>
                        {% endif %}
                    </td>
                </tr>
                {% endfor %}
                </tbody>
                </table>
            {% endfor %}
        {% endif %}


        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        <!--结项图片-->
        <div class="well well-sm">结项图片</div>
        {% if demand_finish_img %}
            <table id="finish-img-choices-table"
                   class="table table-bordered table-hover table-condensed table-striped">
                <thead>
                <tr>
                    <th>图片</th>
                    <th>结项人</th>
                    <th>提交时间</th>
                    <th>公司</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>
                        <a href="{{ demand_finish_img.img_url|safe }}"
                           class="fancybox">
                            <img height="200"
                                 src="{{ demand_finish_img.img_url|safe }}"
                                 alt="结项图片"/>
                        </a>
                    <td>{{ demand_finish_img.owner.nickname }}</td>
                    <td>{{ demand_finish_img.created_datetime }}</td>
                    <td>{{ demand_finish_img.owner.com }}</td>
                </tr>
                </tbody>
            </table>
        {% else %}
            <table id="finish-img-choices-table"
                   class="table table-bordered table-hover table-condensed table-striped">
                <thead>
                <tr>
                    <th></th>
                    <th>图片</th>
                    <th>申请人</th>
                    <th>申请时间</th>
                    <th>申请公司</th>
                </tr>
                </thead>
                <tbody>
                {% for item in form.finish_img_id %}
                    <label class="control-label">
                        <tr>
                            <td>
                                {{ item()|safe }}
                            </td>
                            {% if item.label.text==' ' %}
                                <td>无图片</td>
                                <td></td>
                                <td></td>
                                <td></td>
                            {% else %}
                                <td>
                                    <a href="{{ item.label.text|safe }}"
                                       class="fancybox">
                                        <img height="200"
                                             src="{{ item.label.text|safe }}"
                                             alt="结项图片"/>
                                    </a>
                                </td>
                                <td>{{ finish_img_map[item._value()].owner.nickname }}</td>
                                <td>{{ finish_img_map[item._value()].created_datetime }}</td>
                                <td>{{ finish_img_map[item._value()].owner.com }}</td>
                            {% endif %}
                        </tr>
                    </label>
                {% endfor %}
                </tbody>
            </table>
        {% endif %}

        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        <!--跟进记录-->
{#        <div class="well well-sm">跟进记录</div>#}
{#        <table class="table table-bordered table-hover table-condensed table-striped">#}
{#            {% if comments %}#}
{#                <thead>#}
{#                <tr>#}
{#                    <th>客服昵称</th>#}
{#                    <th>跟进内容</th>#}
{#                    <th>跟进时间</th>#}
{#                </tr>#}
{#                </thead>#}
{#                <tbody>#}
{#                {% for comment in comments %}#}
{#                    <tr>#}
{#                        <td>{{ comment.owner.nickname }}</td>#}
{#                        <td>{{ comment.content }}</td>#}
{#                        <td>{{ comment.created_datetime }}</td>#}
{#                    </tr>#}
{#                {% endfor %}#}
{#                </tbody>#}
{#            {% else %}#}
{#                <tr>#}
{#                    <td>无</td>#}
{#                </tr>#}
{#            {% endif %}#}
{#        </table>#}

        <div class="form-group col-xs-12">
            <button type="submit" name="submit"
                    class="btn btn-success pull-right">保存
            </button>
        </div>

    </form>

    <div class="modal fade" id="feedback_refuse_modal" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">反馈驳回</h4>
                </div>
                <div class="modal-body">
                    <form class="form" id="feedback_refuse_form">
                        <input type="hidden" name="partic_id">
                        <div class="form-group">
                            <div class="row">
                                <label class="control-label  col-xs-4 col-xs-offset-1"
                                       for="">扣除成就值(0-4):</label>
                                <div class="col-xs-6">
                                    <input type="text" class="form-control"
                                           name="minus_credit" value="4" required>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="row">
                                <label class="control-label  col-xs-4 col-xs-offset-1"
                                       for="">驳回理由:</label>
                                <div class="col-xs-6">
                                    <input type="text" class="form-control"
                                           name="feedback_refuse_content" required>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-offset-4">
                                <input type="submit" class="btn btn-danger" id="refuse_feedback_submit"
                                       value="提交">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="follow_modal" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">跟进: <span id="partic_follower_name"></span></h4>
                </div>
                <div class="modal-body">
                    <form action="{{ url_for('op_bp.win_bid_follow') }}"
                          class="form" id="win_bid_follow_form" method="post">
                        <div class="form-group">
                            <input type="hidden" name="partic_id" id="follower_partic_id">
                            <div class="row">
                                <label class="control-label  col-xs-4 col-xs-offset-1"
                                       for="reason">跟进状态:</label>
                                <div class="col-xs-6">
                                    <select class="form-control"
                                           name="follow_type"
                                           id="follow_type">
                                        <option value="0">未跟进</option>
                                        <option value="1">独家锁定</option>
                                        <option value="2">继续跟进</option>
                                        <option value="3">放弃跟进</option>
                                    </select>
                                </div>
                            </div>
                            <div class="row" id="minus_credit_row" hidden>
                                <label class="control-label  col-xs-4 col-xs-offset-1"
                                       for="reason">扣成就值(0-4):</label>
                                <div class="col-xs-6">
                                    <input type="number" class="form-control"
                                           name="minus_credit" value="4" max="4" min="0"
                                           id="minus_credit">
                                </div>
                            </div>
                            <div class="row">
                                <label class="control-label  col-xs-4 col-xs-offset-1"
                                       for="reason">跟进信息:</label>
                                <div class="col-xs-6">
                                    <input type="text" class="form-control"
                                           name="follow_msg"
                                           id="follow_msg">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-offset-4">
                                <input type="submit" class="btn btn-danger"
                                       value="提交">
                            </div>
                        </div>
                    </form>
                    <p style="color: red;" class="col-xs-offset-1">备注: "放弃跟进"与"独家锁定"均为不可逆操作, 请谨慎操作</p>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block scripts %}
    {{ super() }}
    <script src="https://cdn.bootcss.com/fancybox/3.1.20/jquery.fancybox.min.js"></script>
    <script>
        $(document).ready(function () {
            $('.win_follow').click(function () {
                $('#partic_follower_name').html($(this).data('nickname'));
                $('#follower_partic_id').val($(this).data('partic-id'));
                $('#follow_type').val($(this).data('follow-type')).change();
                $('#follow_msg').val($(this).data('follow-msg'));
                $('#follow_modal').modal()
            });

            $('#follow_type').change(function () {
                if($(this).val() == '3'){
                    $('#minus_credit_row').show()
                }else{
                    $('#minus_credit_row').hide()
                }
            });

            function hide_select2_input(tags) {
                for (index in tags) {
                    $('#' + tags[index]).hide();
                    $('#' + tags[index]).next('.select2').hide();
                    $('label[for=' + tags[index] + ']').hide();
                }
            }

            function hide_input(tags) {
                for (index in tags) {
                    $('#' + tags[index]).hide();
                    $('label[for=' + tags[index] + ']').hide();
                }
            }

            function show_select2_input(tags) {
                for (index in tags) {
                    $('#' + tags[index]).show();
                    $('#' + tags[index]).next('.select2').show();
                    $('label[for=' + tags[index] + ']').show();
                }
            }

            function show_input(tags) {
                for (index in tags) {
                    $('#' + tags[index]).show();
                    $('label[for=' + tags[index] + ']').show();
                }
            }

            $(".fancybox").fancybox(
                {'type': 'image'}
            );
            change_malf_state();
            $('#type').val('{{ demand.type }}');
            // 省份与城市联动
            function get_city_choices() {
                var prov_name = $("#prov").val();
                $.ajax({
                    url: "{{ url_for('op_bp.ajax_get_cities') }}" + "?prov_name=" + prov_name,
                    cache: true
                }).done(function (data) {
                    var city_val = $("#city").val();
                    // console.log(city_val);
                    $("#city").empty();
                    for (var i = 0; i < data["choices"].length; i++) {
                        var id = data["choices"][i]["id"];
                        var name = data["choices"][i]["name"];
                        $("#city").append(
                            "<option value='" + id + "'>" + name + "</option>"
                        );
                    }
                    $("#city").val(city_val);
                }).fail(function () {
                    alert("获取城市列表失败，请联系系统管理员!")
                });
            }

            // 初始化城市选项
            get_city_choices();
            // 绑定省份change事件
            $("#prov").change(function () {
                get_city_choices();
            });

            function change_malf_state() {
                var val = $('#cate').val();
                // 是否显示 维修--故障分类
                if (val == '2') {
                    show_select2_input(new Array('malf'));
                } else {
                    hide_select2_input(new Array('malf'));
                }

                // 安装/维修时是一种类型
                if (val == '1' || val == '2') {
                    $("#type").empty();
                    {% for key, value in demand_type_dic.items() %}
                        $("#type").append(
                            "<option value='" + {{ key }} +"'>" + '{{ value }}' + "</option>"
                        );
                    {% endfor %}
                } else {
                    // 租赁时是一种类型
                    $("#type").empty();
                    {% for key, value in demand_rent_type_dic.items() %}
                        $("#type").append(
                            "<option value='" + {{ key }} +"'>" + '{{ value }}' + "</option>"
                        );
                    {% endfor %}
                }
            }

            $('#cate').change(function () {
                change_malf_state()

            });

            // 电话号码与电话录音联动
            function get_user_audios() {
                var user_mobile = $("#user_mobile").val();
                $.ajax({
                    url: "{{ url_for('op_bp.ajax_get_user_audios') }}" + "?user_mobile=" + user_mobile,
                    cache: true
                }).done(function (data) {
                    $("#audio-choices label").remove();
                    for (var i = 0; i < data.length; i++) {
                        var id = data[i]["id"];
                        var src = data[i]["src"];
                        var record_date = data[i]["record_date"];
                        if (id == -1) {
                            $("#audio-choices").append(
                                "<label class='control-label'><input id='audio-" + i + "' name='audio_id' type='radio' value='" + id + "'>无录音</label>"
                            );
                        } else {
                            $("#audio-choices").append(
                                "<label class='control-label'><input id='audio-" + i + "' name='audio_id' type='radio' value='" + id + "'><audio src='" + src + "' controls='controls'>您的浏览器无法播放该音频。</audio>录音日期：" + record_date
                            );
                        }
                        $("#audio-choices").append("<div class='clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block'></div>"
                        )
                    }
                }).fail(function () {
                    alert("查询用户录音失败，请联系系统管理员!")
                });
            }

            $('#sync_audio').click(function () {
                get_user_audios()
            });
            
            $('#refuse_feedback_submit').click(function () {
                var partic_id = $('input[name=partic_id]').val();
                var minus_credit = $('input[name=minus_credit]').val();
                var feedback_refuse_content = $('input[name=feedback_refuse_content]').val();

                minus_credit = parseInt(minus_credit);
                if(isNaN(minus_credit)){
                    alert('请输入0-4的数字');
                    return
                }
                if(minus_credit < 0 || minus_credit > 4){
                    alert('扣除成就值必须在0-4之间');
                    return
                }
                var flag = confirm('请确认要驳回此请求?');
                if(flag === false || flag === null){
                    return
                }
                $.ajax({
                    url: "{{ url_for('op_bp.ajax_approval_feedback')}}",
                    data: JSON.stringify({
                        'partic_id': partic_id,
                        'feedback_status': 1,
                        'minus_credit': minus_credit,
                        'feedback_refuse_content': feedback_refuse_content
                    }),
                    type: 'put',
                    dataType: 'json',
                    contentType: 'application/json',
                    cache: true
                }).done(function (data) {
                    if (data.feedback_status) {
                        alert('审核成功');
                        location.reload();
                    }

                }).fail(function () {
                    alert("审核失败")
                });
            });

            $('#feedback-info .feedback-btn').each(function (i, obj) {
                $(obj).click(function () {
                    var partic_id = $(this).data('partic_id');
                    var feedback_status = $(this).data('feedback_status');
                    var flag;

                    flag = confirm('请确认要通过此请求?');
                    if(flag === false || flag === null){
                        return;
                    }
                    $.ajax({
                        url: "{{ url_for('op_bp.ajax_approval_feedback')}}",
                        data: JSON.stringify({
                            'partic_id': partic_id,
                            'feedback_status': feedback_status
                        }),
                        type: 'put',
                        dataType: 'json',
                        contentType: 'application/json',
                        cache: true
                    }).done(function (data) {
                        if (data.feedback_status) {
                            alert('审核成功');
                            location.reload();
                        }

                    }).fail(function () {
                        alert("审核失败")
                    });
                });
            });

            $('.feedback-refuse-btn').click(function(){
                $('input[name=partic_id]').val($(this).data('partic_id'));
                $('#feedback_refuse_modal').modal()
            });

            $("#edit-demand-form").submit(function(){
                $('#edit-demand-form button[name="submit"]').prop('disabled', true);
                return true;
            })
        });
    </script>

{% endblock %}
